import {Component}from "react"
class DemoA extends Component{
    constructor(){
        super();//调用父组件的constructor
        console.log("constructor...");
        this.state= {
            couter:1,
            num:0
        }
    }
    componentDidMount(){
        // console.log("componentDidMount..");
        this.refs.box.style.color ='red'
    }
    componentDidUpdate(props,state){
        console.log(state);
        console.log("componentDidUpdate...");
        if(state.num ==this.state.num){
            this.setState(stat=>({num:stat.num+1}))
            
        }
    }
    add(){
        this.setState({
            couter:this.state.couter + 1
        })
    }
    render(){
        let {couter}=this.state;
        console.log("render..")
        return( 
            <div>
                <h1 ref="box">类组件--{couter}</h1>
                <button onClick={()=>this.add()}>+1</button>
            </div>
        )
    }
}
export default DemoA